﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

namespace web
{
    public partial class Formulario_web14 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Header.Title = "Inicio de sesion";

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            bool passOk = false, userOk = false;



            Session["usuario"] = Login1.UserName;
            Session["pass"] = Login1.Password;


            ENLibraryClass.ENClientes cliente = new ENLibraryClass.ENClientes();
            DataTable dtCliente = cliente.BuscarClientes();

            for (int i = 0; i < dtCliente.Rows.Count; i++)
            {
                if (dtCliente.Rows[i]["login"].ToString() == Session["usuario"].ToString())
                    userOk = true;
                if (dtCliente.Rows[i]["password"].ToString() == Session["pass"].ToString())
                    passOk = true;
            }

            if (userOk && passOk == true)
            {

                bool Authenticated = true;
                e.Authenticated = Authenticated;


                Response.Redirect("default.aspx");

            }
            else
            {
                bool Authenticated = false;
                e.Authenticated = Authenticated;
                Session.Clear();
                Session.Abandon();
            }

        }
    }
}
